//
//  SetVC.m
//  Login
//
//  Created by mac on 17/2/23.
//  Copyright © 2017年 ZF. All rights reserved.
//

#import "SetVC.h"
#import "SetViewCell.h"
#import "SetVC_SecondFloor.h"
#import "NetworkLink.h"
#import "SetVCTableViewCell.h"
#import "VersionTableViewController.h"

@interface SetVC ()
{
    NSString *username;
    NSArray *data;
}
@end

@implementation SetVC

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.hidesBottomBarWhenPushed = YES;
    self.tabBarController.tabBar.hidden = NO;
    AppDelegate *delegate = [Helps app];
    username = @"用户名:";
    data = @[@"检查版本",@"关于"];
    username = [username stringByAppendingString:delegate.userName];
     [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.scrollEnabled = NO;
    self.tableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
    self.tabBarController.hidesBottomBarWhenPushed = YES;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section == 0)
    {
        return 1;
    }
    if(section == 1)
    {
        return data.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = COLOR(215, 215, 215, 1);
    if(indexPath.section == 0)
    {
        SetViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"USER" forIndexPath:indexPath];
        cell.label.text =  username;
        view.frame = CGRectMake(0, 79, tableView.frame.size.width, 1);
        [cell addSubview:view];
        return cell;
    }
    if(indexPath.section == 1)
    {
        SetVCTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"setVCcell"];
        cell.label.text = data[indexPath.row];
        view.frame = CGRectMake(0, 43, tableView.frame.size.width, 1);
        [cell addSubview:view];
        return cell;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
    {
        return  80;
    }
    return 44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 1)
    {
        return 30;
    }
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 30)];
    view.backgroundColor = COLOR(230, 230, 230, 1);
    return view;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
    {
        SetVC_SecondFloor *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"set2"];
        [self.navigationController pushViewController:vc animated:YES];
    
    }
    if(indexPath.section == 1)
    {
        if(indexPath.row == 0)
        {
            [NetworkLink getCurrentVersionComplete:^(NSString *version) {
                dispatch_sync(dispatch_get_main_queue(), ^{
                    VersionTableViewController *con = [[VersionTableViewController alloc] init];
                    con.vsion = version;
                    [self.navigationController pushViewController:con animated:YES];
                });
            }];
        }
    }
}

- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
